//answer.js
var util = require('../../utils/util.js')

var app = getApp()
Page({
  data: {
    motto: '',
    userInfo: {},
    classInfo:{},
    isorder:true,
    iswatch:false
  },
  //事件处理函数
  // toQuestion: function() {
  //   wx.navigateTo({
  //     url: '../question/question'
  //   })
  // },
  // 添加关注
  addwatch:function(){
    if(!this.data.iswatch){
      this.setData({
        iswatch: true
      })
      wx.showToast({
        title: '关注成功',
        icon: 'success',
        duration: 2000
      })
    }else{
      this.setData({
        iswatch: false
      })
    }
  },
  // 预约
  preorder:function(event){
    var that = this
    if(this.data.isorder){
      wx.showModal({
        title: '预约',
        content: '确定要预约课程?',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            that.orderSuccess();
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      this.orderCancel();
    }
  },
  orderCancel:function(){
    this.setData({
      isorder: true
    })
    wx.showToast({
      title: '已取消',
      icon: 'success',
      duration: 2000
    })
  },
  // 预约成功
  orderSuccess:function(){
    this.setData({
      isorder:false
    })
    wx.showToast({
      title: '预约成功',
      icon: 'success',
      duration: 2000
    })
  },
  orderFail:function(){

  },
  onLoad: function (options) {
    // classid = 3
    console.log(options)
    
    var that = this
    that.setData({
      classInfo:options
    })
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
    // 获取课程信息
    this.getClassInfo();
  },
  tapName: function(event){
    console.log(event)
  },
  // 获取课程信息
  getClassInfo:function(){
    var classes = util.getClassInfo(); 
    var classes_data = classes.data;
    console.log(classes);
    this.setData({
      classinfo:classes_data[0]
    });
  }
})
